<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>需求列表查看</title>
    <header th:replace="header::html"></header>
</head>

<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>业务管理</cite></a>
            <a><cite>需求列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="layui-fluid">
    <div class="layui-row  layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form  layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="ntitle" placeholder="请输入需求标题关键字" autocomplete="off"
                                   class="layui-input">
                        </div>

                        <div class="layui-input-inline">
                            <select name="verifyState" lay-filter="verifyState">
                                <option value="">请选择审核状态</option>
                                <option value="已审核">已审核</option>
                                <option value="待审核">待审核</option>
                                <option value="未过审">未过审</option>
                            </select>
                        </div>

                        <div class="layui-input-inline">
                            <select name="tenderState" lay-filter="tenderState">
                                <option value="">请选择中标状态</option>
                                <option value="已中标">已中标</option>
                                <option value="未中标">未中标</option>
                            </select>
                        </div>

                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="test20" placeholder="请选择开始日期(结束时间)"
                                       name="startDate">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="test21" placeholder="请选择结束日期(结束时间)"
                                       name="endDate">
                            </div>
                        </div>


                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search" permission="back:need:query"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="need" lay-filter="need"></table>
                </div>

                <div class="layui-card-body ">
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="verify" permission="back:need:query">审核</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
                           permission="back:need:delete">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#test20'
			, done: function (value, date) {
				//layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});

		laydate.render({
			elem: '#test21'
			, done: function (value, date) {
				//layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});
	});


	layui.use('table', function () {
		var table = layui.table,
			form = layui.form;
		table.render({
			elem: '#need'
			, url: '/api-back/need/list' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[ //表头
					{type: 'checkbox', fixed: 'left'},
					{title: '序号', type: 'numbers', width: '5%'}
					, {field: 'nid', title: 'ID', align: 'center', sort: true, width: "5%", style: 'display:none;'}
					, {field: 'ntitle', title: '需求标题', align: 'center'}
					, {field: 'nmoney', title: '佣金', align: 'center', sort: true, width: "5%"}
					, {field: 'nstarttime', title: '发布时间', align: 'center'}
					, {field: 'nendtime', title: '结束时间', align: 'center'}
					, {field: 'nrealtime', title: '工期', align: 'center'}
					, {field: 'nstatus', title: '需求状态', align: 'center', width: "5%"}
					, {field: 'nstate', title: '投标状态', align: 'center', width: "5%"}
					, {title: '操作', toolbar: '#barDemo', align: 'center'}
				]
			],
			done: function () {
				$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
			}
		});


		//监听工具条
		table.on('tool(need)', function (obj) {
			var data = obj.data;//获取点击行数据
			if (obj.event === 'del') {
				layer.confirm('确认删除该条需求吗?', function (index) {
					if (data.nstatus === '未过审') {
						$.ajax({
							url: "/api-back/need/delete",
							type: "GET",
							data: {nid: data.nid},
							dataType: 'json',
							success: function (result) {
								layer.alert("删除成功", {icon: 1}, function (index1) {
									layer.close(index1);
									table.reload('need');
									$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
								});
							},
							error: function () {
								//window.location.href = "/404.html";
								layer.open({
									type: 2,
									content: "/404.html",
									area: ['60%', '60%'],
									title: '权限不足'
								});
							}
						});
					} else {
						layer.msg('只有未过审的需求才可以删除，请确认！', {icon: 2});
					}
				});
			} else if (obj.event === 'verify') {
				alert(data.nstatus);
				if (data.nstatus == '待审核') {
					xadmin.open('审核需求页面', '/api-back/need/verify/?nid=' + data.nid);
				} else {
					layer.msg('只有待审核的需求才可以进行审核，请确认！', {icon: 2});
				}
			}
		});

		//搜索
		form.on('submit(search)', function (data) {
			var data = data.field;
			table.render({
				elem: '#need'
				, url: '/api-back/need/findNeedByFuzzyNeedTitle' //数据接口
				, page: true //开启分页
				, where: {
					"ntitle": data.ntitle,
					"verifyState": data.verifyState,
					"tenderState": data.tenderState,
					"startTime": data.startDate,
					"endTime": data.endDate
				}
				, response: {
					countName: 'count', //规定数据总数的字段名称，默认：count
					dataName: 'datas' //规定数据列表的字段名称，默认：data
				}
				, cols: [
					[ //表头
						{type: 'checkbox', fixed: 'left'},
						{title: '序号', type: 'numbers', width: '5%'}
						, {field: 'nid', title: 'ID', align: 'center', sort: true, width: "5%", style: 'display:none;'}
						, {field: 'ntitle', title: '需求标题', align: 'center'}
						, {field: 'nmoney', title: '佣金', align: 'center', sort: true, width: "5%"}
						, {field: 'nstarttime', title: '发布时间', align: 'center'}
						, {field: 'nendtime', title: '结束时间', align: 'center'}
						, {field: 'nrealtime', title: '工期', align: 'center'}
						, {field: 'nstatus', title: '需求状态', align: 'center', width: "5%"}
						, {field: 'nstate', title: '投标状态', align: 'center', width: "5%"}
						, {title: '操作', toolbar: '#barDemo', align: 'center'}
					]
				],
				done: function () {
					$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
				},
				error: function () {
					layer.open({
						type: 2,
						content: "/404.html",
						area: ['60%', '60%'],
						title: '权限不足'
					});
				}
			});
			return false;
		});
	});
</script>
</html>